package com.im.partchat.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.im.partchat.R;
import com.im.partchat.bean.FriendApply;

@SuppressWarnings("deprecation")
public class NewFriendListAdapter extends BaseAdapters {

    public NewFriendListAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.pt_ada_user_ship, parent, false);
            holder.mName = (TextView) convertView.findViewById(R.id.ship_name);
            holder.mMessage = (TextView) convertView.findViewById(R.id.ship_message);
            holder.mHead = (ImageView) convertView.findViewById(R.id.new_header);
            holder.mState = (TextView) convertView.findViewById(R.id.ship_state);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        final FriendApply bean = (FriendApply) dataSet.get(position);
        holder.mName.setText(bean.getName());

        holder.mMessage.setText("");
        holder.mState.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mOnItemButtonClick != null) {
                    mOnItemButtonClick.onButtonClick(position, v, bean.getState());
                }
            }
        });

        switch (bean.getState()) {
            case 1:
                holder.mState.setText(R.string.agree);
                holder.mState.setBackground(mContext.getResources().getDrawable(R.drawable.de_add_friend_selector));
                break;
            case 2:
                holder.mState.setText(R.string.added);
                holder.mState.setBackgroundDrawable(null);
                break;
            case 3:
                holder.mState.setText(R.string.request);
                holder.mState.setBackgroundDrawable(null);
                break;
//            case 11: //收到了好友邀请
//                holder.mState.setText(R.string.agree);
//                holder.mState.setBackgroundDrawable(mContext.getResources().getDrawable(R.drawable.de_add_friend_selector));
//                break;
//            case 10: // 发出了好友邀请
//                holder.mState.setText(R.string.request);
//                holder.mState.setBackgroundDrawable(null);
//                break;
//            case 21: // 忽略好友邀请
//                holder.mState.setText(R.string.ignore);
//                holder.mState.setBackgroundDrawable(null);
//                break;
//            case 20: // 已是好友
//                holder.mState.setText(R.string.added);
//                holder.mState.setBackgroundDrawable(null);
//                break;
//            case 30: // 删除了好友关系
//                holder.mState.setText(R.string.deleted);
//                holder.mState.setBackgroundDrawable(null);
//                break;
        }
        return convertView;
    }

    class ViewHolder {
        ImageView mHead;
        TextView mName;
        TextView mState;
        //        TextView mtime;
        TextView mMessage;
    }

    OnItemButtonClick mOnItemButtonClick;


    public void setOnItemButtonClick(OnItemButtonClick onItemButtonClick) {
        this.mOnItemButtonClick = onItemButtonClick;
    }

    public interface OnItemButtonClick {
        boolean onButtonClick(int position, View view, int status);

    }
}
